import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:device_info/device_info.dart';
import 'package:dio/dio.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter_app_study/Single/SIngleUserEntity.dart';
import 'package:flutter_app_study/bean/Test.dart';
import 'package:flutter_app_study/bean/up_data_entity.dart';
import 'package:flutter_app_study/generated/json/up_data_entity_helper.dart';

import '../cost/ErpUrl.dart';
import 'DioUtil.dart';

///可以按需要添加拦截器，实现一些通用的功能，例如统一的请求头，统一的参数添加

class CommonHeaderInterceptor extends Interceptor {
  @override
  Future<FutureOr> onRequest(RequestOptions options) async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    if (Platform.isAndroid) {
      AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
      options.headers.addAll({"device": androidInfo.model, "requestId": "ddfsgg"});
    } else {
      IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
      options.headers.addAll({"device": iosInfo.utsname.machine, "requestId": "ddfsgg"});
    }
    return super.onRequest(options);
  }
}

class ErrorInterceptor extends Interceptor {
  @override
  Future<FutureOr> onError(DioError err) async {
    print(err.type); //也可以区分类型，自定义message;
    return super.onError(err);
  }
}
